from fastapi import APIRouter, HTTPException, Query, Depends
from typing import List
from ..services.movie_service import MovieService
from ..schemas.movie import MovieResponse, MovieRecommendation
from ..dependencies import get_movie_service
from ..core.config import settings

router = APIRouter(
    prefix=f"{settings.API_V1_STR}/movies",
    tags=["movies"]
)

@router.get("/trending")
async def get_trending_movies(
    page: int = Query(default=1, ge=1),
    page_size: int = Query(default=12, ge=1, le=50),
    movie_service: MovieService = Depends(get_movie_service)
):
    """获取热门电影"""
    result = movie_service.get_trending_movies(page, page_size)
    if not result["movies"]:
        raise HTTPException(status_code=404, detail="No trending movies found")
    return result

@router.get("/{movie_id}/recommendations", response_model=List[MovieRecommendation])
async def get_recommendations(
    movie_id: str,
    limit: int = Query(default=5, ge=1, le=20),
    movie_service: MovieService = Depends(get_movie_service)
):
    """获取电影推荐"""
    recommendations = movie_service.get_recommendations(movie_id, limit)
    if not recommendations:
        raise HTTPException(status_code=404, detail="No recommendations found")
    return recommendations

@router.get("/{movie_id}", response_model=MovieResponse)
async def get_movie(
    movie_id: str,
    movie_service: MovieService = Depends(get_movie_service)
):
    """获取电影详情"""
    movie = movie_service.get_movie(movie_id)
    if not movie:
        raise HTTPException(status_code=404, detail="Movie not found")
    return movie 